package m202405.d13;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/5/13 15:32
 */
public class Q108 {
    public TreeNode sortedArrayToBST(int[] nums) {
        return build(nums, 0, nums.length);
    }

    private TreeNode build(int[] nums, int start, int end) {
        if (start >= end) {
            return null;
        }
        int mid = (start + end) / 2;
        TreeNode root = new TreeNode(nums[mid]);
        root.left = build(nums, start, mid);
        root.right = build(nums, mid + 1, end);
        return root;
    }
}
